Telegram Group & Telegram Channel
In the previous post, we had the following code:

python
import asyncio

async def child():
...

async def main():
asyncio.create_task(child())
...

Can you spot a bug?

Since we don't store a reference to the background task we create, the garbage collector may destroy the task before it finishes. To avoid that, we need to store a reference to the task until it finishes. The official documentation recommends the following pattern:

python
bg_tasks = set()

async def main():
t = asyncio.create_task(child())

# hold the reference to the task
# in a global set
bg_tasks.add(t)

# automatically remove the task
# from the set when it's done
t.add_done_callback(bg_tasks.discard)

...



tg-me.com/pythonetc/725
Create:
Last Update:

In the previous post, we had the following code:

python
import asyncio

async def child():
...

async def main():
asyncio.create_task(child())
...

Can you spot a bug?

Since we don't store a reference to the background task we create, the garbage collector may destroy the task before it finishes. To avoid that, we need to store a reference to the task until it finishes. The official documentation recommends the following pattern:

python
bg_tasks = set()

async def main():
t = asyncio.create_task(child())

# hold the reference to the task
# in a global set
bg_tasks.add(t)

# automatically remove the task
# from the set when it's done
t.add_done_callback(bg_tasks.discard)

...

BY Python etc


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 280

Share with your friend now:
tg-me.com/pythonetc/725

View MORE
Open in Telegram


Python etc Telegram | DID YOU KNOW?

Date: |

What is Telegram?

Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.

Python etc from sa


Telegram Python etc
FROM USA